function deepClone(obj, map = new WeakMap()) {
    if (!obj || typeof obj !== 'object') {
        return obj;
    }
    if (map.has(obj)) {
        return map.get(obj);
    }
    let newObj = Array.isArray(obj) ? [] : {};
    map.set(obj, newObj);
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            newObj[key] = typeof obj[key] === 'object' ? deepClone(obj[key],map) : obj[key];
        }
    }
    return newObj;
}